<template>
	<view class="myOuter">
		<!-- 顶部 -->
		<view class="myTop">
			<image src="http://192.144.206.29/wap/static/image/member-bg.png" mode=""></image>
			<view class="myInfoY" v-if="token">
				<image :src="userData.avatar" mode=""></image>
				<view class="">
					{{userData.nickname}}
				</view>
				<view class="">
					{{userData.grade_name}}
				</view>
			</view>
			<view class="myInfoN" v-else>
				<image src="../../static/logo.png" mode=""></image>
				<button @click="toLogin">登录/注册</button>
			</view>
		</view>

		<view class="orderOuter">
			<!-- 我的订单 -->
			<view class="myOrder">
				<view class="myOrder_top" @click="order(0)">
					<view class="myOrder_top_l">
						<image src="../../static/images/iconImg/mydingdan.png" mode=""></image>
						<text>我的订单</text>
					</view>
					<view class="myOrder_top_r">
						<image src="../../static/images/iconImg/yjt.png" mode=""></image>
					</view>
				</view>
				<ul class="myOrder_main">
					<li @click="order(1)">
						<image src="../../static/images/iconImg/mydingdan/待付款.png" mode=""></image>
						<view class="">
							待付款<text v-if="orderNum['1']&&orderNum['1']!==0">{{orderNum['1']}}</text>
						</view>
					</li>
					<li @click="order(2)">
						<image src="../../static/images/iconImg/mydingdan/待发货.png" mode=""></image>
						<view class="">
							待发货<text v-if="orderNum['2']&&orderNum['2']!==0">{{orderNum['2']}}</text>
						</view>
					</li>
					<li @click="order(3)">
						<image src="../../static/images/iconImg/mydingdan/待收货.png" mode=""></image>
						<view class="">
							待收货<text v-if="orderNum['3']&&orderNum['3']!==0">{{orderNum['3']}}</text>
						</view>
					</li>
					<li @click="order(4)">
						<image src="../../static/images/iconImg/mydingdan/待评价.png" mode=""></image>
						<view class="">
							待评价<text v-if="orderNum['4']&&orderNum['4']!==0">{{orderNum['4']}}</text>
						</view>
					</li>
					<li>
						<image src="../../static/images/iconImg/mydingdan/待评价.png" mode=""></image>
						<view class="">
							待退货<text v-if="orderNum['isAfterSale']&&orderNum['isAfterSale']!==0">{{orderNum['isAfterSale']}}</text>
						</view>
					</li>
				</ul>
			</view>

			<!-- 我的服务 -->
			<view class="meServer">
				<view class="myOrder_top">
					<view class="myOrder_top_l">
						<image src="../../static/images/iconImg/myservice.png" mode=""></image>
						<text>我的服务</text>
					</view>

				</view>
				<ul class="myOrder_main">
					<li v-for="item in server" :key="item.id" @click="serverBtn(item)">
						<image :src="item.iconUrl" mode=""></image>
						<view class="">
							{{item.title}}
						</view>
					</li>
				</ul>
			</view>

			<!-- 其它 -->
			<view class="orther">
				<view class="myOrder_top">
					<view class="myOrder_top_l">
						<image src="../../static/images/iconImg/myelse.png" mode=""></image>
						<text>其它</text>
					</view>

				</view>
				<ul class="myOrder_main">
					<li>
						<image src="../../static/images/iconImg/myelse/记录.png" mode=""></image>
						<view class="">
							砍价记录
						</view>
					</li>
					<li>
						<image src="../../static/images/iconImg/myelse/邀请好友.png" mode=""></image>
						<view class="">
							邀请好友
						</view>
					</li>
					<li @click="systemSet">
						<image src="../../static/images/iconImg/myelse/设置.png" mode=""></image>
						<view class="">
							系统设置
						</view>
					</li>
					<li>
						<image src="../../static/images/iconImg/myelse/电话.png" mode=""></image>
						<view class="">
							联系客服
						</view>
					</li>
				</ul>
			</view>

		</view>

	</view>
</template>

<script>
	import {
		getUerInfoApi
	} from '../../api/paiModule/login.js'
	export default {
		data() {
			return {
				loginFlag: false,
				token: '',
				userData: {},
				server: [{
						id: '0',
						title: '我的优惠券',
						iconUrl: '../../static/images/iconImg/myservice/我的优惠券.png'
					},
					{
						id: '1',
						title: '我的余额',
						iconUrl: '../../static/images/iconImg/myservice/余额.png'
					},
					{
						id: '2',
						title: '我的发票',
						iconUrl: '../../static/images/iconImg/myservice/发票.png'
					},
					{
						id: '3',
						title: '我的积分',
						iconUrl: '../../static/images/iconImg/myservice/积分明细.png'
					},
					{
						id: '4',
						title: '地址管理',
						iconUrl: '../../static/images/iconImg/myservice/地址.png'
					},
					{
						id: '5',
						title: '我的收藏',
						iconUrl: '../../static/images/iconImg/myservice/收藏.png'
					},
					{
						id: '6',
						title: '我的足迹',
						iconUrl: '../../static/images/iconImg/myservice/足迹.png'
					},
				],
				orderNum: {},
				sxFlag: false
			};
		},
		created() {
			const token = uni.getStorageSync('token')
			this.token = token
		},
		mounted() {
			// this.getUserInfo()
		},
		onShow() {
			this.getUserInfo()
			this.getOrderNum()
		},
		methods: {
			// 去登陆
			toLogin() {
				uni.navigateTo({
					url: '/pages/login/login'
				})
			},

			// 获取用户登录信息
			async getUserInfo() {
				const {
					data: res
				} = await getUerInfoApi({
					method: "user.info",
					token: uni.getStorageSync('token')
				})
				this.userData = res.data

			},

			serverBtn(data) {
				switch (data.title) {
					case '我的收藏':
						uni.navigateTo({
							url: '/pages/collect/collect'
						})
						break;
					case '地址管理':
						uni.navigateTo({
							url: '/pages/address/address'
						})
						break;
				}
			},

			// 去订单列表界面
			order(index) {
				uni.navigateTo({
					url: '/pages/orderList/orderList?index=' + index
				})
			},

			// 获取订单数量
			async getOrderNum() {
				const {
					data: res
				} = await getUerInfoApi({
					ids: "1,2,3,4",
					isAfterSale: true,
					method: "order.getorderstatusnum",
					token: uni.getStorageSync('token')
				})

				this.orderNum = res.data
			},

			// 系统设置
			systemSet() {
				uni.navigateTo({
					url: '/pages/systemSet/systemSet'
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.myOuter {
		height: 92.5vh;

		.myTop {
			height: 160px;
			border: 1px solid orange;
			position: relative;

			image {
				width: 100%;
				height: 100%;
			}

			.myInfoY,
			.myInfoN {
				position: absolute;
				top: 50%;
				left: 50%;
				transform: translate(-50%, -50%);
				color: #fff;
				font-size: 12px;
				line-height: 20px;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;

				image {
					width: 80px;
					height: 80px;
					border-radius: 50%;
					margin-bottom: 6px;
				}
			}

			.myInfoN {
				button {
					width: 100px;
					height: 24px;
					font-size: 12px;
					line-height: 24px;
					color: #fff;
					border-radius: 100px;
					background-color: #ff7159;
				}
			}
		}

		.orderOuter {
			height: 70vh;
			background-color: #f1f1f1;
		}


		.myOrder {
			background-color: #fff;

			.myOrder_top {
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 10px;
				border-bottom: 1px solid #e2e2e2;

				.myOrder_top_l {
					display: flex;
					align-items: center;
					font-size: 12px;

					image {
						width: 20px;
						height: 20px;
						margin-right: 10px;
					}
				}

				.myOrder_top_r {
					image {
						width: 20px;
						height: 20px;
					}
				}
			}

			.myOrder_main {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 10px;

				li {
					width: 20%;
					display: flex;
					flex-direction: column;
					align-items: center;
					justify-content: center;
					font-size: 12px;
					position: relative;

					image {
						width: 26px;
						height: 26px;
						margin-bottom: 6px;
					}

					&>view {
						&>text {
							color: #ff7159;
							position: absolute;
							top: -6px;
							right: 16%;
							display: inline-block;
							color: #fff;
							background-color: #ff7159;
							border-radius: 50%;
							font-size: 12px;
							padding: 1px 4px;
							transform: scale(0.7);
							transform-origin: left top
						}
					}
				}
			}
		}

		.meServer {
			margin-top: 10px;
			background-color: #fff;

			.myOrder_top {
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 10px;
				border-bottom: 1px solid #e2e2e2;

				.myOrder_top_l {
					display: flex;
					align-items: center;
					font-size: 12px;

					image {
						width: 20px;
						height: 20px;
						margin-right: 10px;
					}
				}

				.myOrder_top_r {
					image {
						width: 20px;
						height: 20px;
					}
				}
			}

			.myOrder_main {
				height: 120px;
				overflow: hidden;
				display: flex;
				align-items: center;
				justify-content: flex-start;
				flex-wrap: wrap;
				padding: 10px;

				li {
					width: 24%;
					display: flex;
					flex-wrap: wrap;
					flex-direction: column;
					align-items: center;
					justify-content: center;
					font-size: 12px;
					margin-bottom: 20px;

					image {
						width: 20px;
						height: 20px;
						margin-bottom: 10px;
					}
				}
			}
		}

		.orther {
			background-color: #fff;
			margin-top: 10px;

			.myOrder_top {
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 10px;
				border-bottom: 1px solid #e2e2e2;

				.myOrder_top_l {
					display: flex;
					align-items: center;
					font-size: 12px;

					image {
						width: 20px;
						height: 20px;
						margin-right: 10px;
					}
				}

				.myOrder_top_r {
					image {
						width: 20px;
						height: 20px;
					}
				}
			}

			.myOrder_main {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 10px 30px;

				li {
					width: 18%;
					display: flex;
					flex-direction: column;
					align-items: center;
					justify-content: center;
					font-size: 12px;

					image {
						width: 24px;
						height: 24px;
						margin-bottom: 10px;
					}
				}
			}
		}
	}
</style>